From 58a161fa356a51e2deaa22008c1465e18c8a2ad7 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Fri, 6 Dec 2013 12:53:18 -0500 Subject: [PATCH] Status::getHTML should actually return HTML Currently it only returns wikitext with templates expanded (like Message's text() method). Bug: 45844 Change-Id: I24b5b098f15d0a4194817f31f63e37be1179aae6 --- includes/Message.php | 2 +- includes/Status.php | 11 ++++++----- tests/phpunit/includes/StatusTest.php | 14 ++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/includes/Message.php b/includes/Message.php index 57c6264dfa..1b36193caf 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -841,7 +841,7 @@ class Message { */ protected function parseText( $string ) { $out = MessageCache::singleton()->parse( $string, $this->title, /*linestart*/true, $this->interface, $this->language ); - return is_object( $out ) ? $out->getText() : $out; + return $out instanceof ParserOutput ? $out->getText() : $out; } /** diff --git a/includes/Status.php b/includes/Status.php index 5f5ca7497f..e11ba03bdf 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -301,14 +301,15 @@ class Status { /** * Get the error message as HTML. This is done by parsing the wikitext error * message. - * - * @note: this does not perform a full wikitext to HTML conversion, it merely applies - * a message transformation. - * @todo figure out whether that is actually The Right Thing. + * @param string $shortContext a short enclosing context message name, to + * be used when there is a single error + * @param string $longContext a long enclosing context message name, for a list + * @return String */ public function getHTML( $shortContext = false, $longContext = false ) { $text = $this->getWikiText( $shortContext, $longContext ); - return MessageCache::singleton()->transform( $text, true ); + $out = MessageCache::singleton()->parse( $text, null, true, true ); + return $out instanceof ParserOutput ? $out->getText() : $out; } /** diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 30a554e2a8..a2b707ccf1 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -253,8 +253,8 @@ class StatusTest extends MediaWikiLangTestCase { * this can not really be done now due to use of wfMessage()->plain() * It is possible to mock such methods but only if namespaces are used */ - public function testGetWikiText( Status $status, $expected ) { - $this->assertEquals( $expected, $status->getWikiText() ); + public function testGetWikiText( Status $status, $wikitext, $html ) { + $this->assertEquals( $wikitext, $status->getWikiText() ); } /** @@ -264,8 +264,8 @@ class StatusTest extends MediaWikiLangTestCase { * this can not really be done now due to use of $this->getWikiText using wfMessage()->plain() * It is possible to mock such methods but only if namespaces are used */ - public function testGetHtml( Status $status, $expected ) { - $this->assertEquals( $expected, $status->getHTML() ); + public function testGetHtml( Status $status, $wikitext, $html) { + $this->assertEquals( $html, $status->getHTML() ); } /** @@ -279,6 +279,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ 'GoodStatus' ] = array( new Status(), "Internal error: Status::getWikiText called for a good result, this is incorrect\n", + "

Internal error: Status::getWikiText called for a good result, this is incorrect\n

", ); $status = new Status(); @@ -286,6 +287,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ 'GoodButNoError' ] = array( $status, "Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n", + "

Internal error: Status::getWikiText: Invalid result object: no error text but not OK\n

", ); $status = new Status(); @@ -293,6 +295,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ '1StringWarning' ] = array( $status, "", + "

<fooBar!>\n

", ); $status = new Status(); @@ -301,6 +304,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ '2StringWarnings' ] = array( $status, "* \n* \n", + "
    \n
  • <fooBar!>\n
  • \n
  • <fooBar2!>\n
  • \n
\n", ); $status = new Status(); @@ -308,6 +312,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ '1MessageWarning' ] = array( $status, "", + "

<fooBar!>\n

", ); $status = new Status(); @@ -316,6 +321,7 @@ class StatusTest extends MediaWikiLangTestCase { $testCases[ '2MessageWarnings' ] = array( $status, "* \n* \n", + "
    \n
  • <fooBar!>\n
  • \n
  • <fooBar2!>\n
  • \n
\n", ); return $testCases; -- 2.20.1